class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            time: 0,
            playing:!0,
            shannum: 2,
            data: {
                one: '',
                two: '',
                three: '',
                four: '',
            },
        };
    }









    componentDidMount() {

        配置微信('main')
        function playBackgroundMusic() {
            //  makeLog('play');
            var bgMusic = document.getElementById('bgmusic');
            console.log(bgMusic, 'bgMusic---');
            bgMusic.play();
            this.setState({ playing: !0 })
        }
        document.addEventListener(
            'WeixinJSBridgeReady',
            function () {
                console.log('WeixinJSBridgeReady---');
                // makeLog('WeixinJSBridgeReady');
                playBackgroundMusic();
                  
            },
            false
        );

        let myphone = localStorage.getItem('phone')
        if (myphone != null) {
            myphone = maskPhoneNumber(myphone)
            this.setState({ myphone })
        }
        if (Constant.SWITCH_VCONSOLE) {
            new VConsole();
        }



        当前碎片(res => {
            if (res.data) {
                let { data } = res, shannum = -1, canchou = !1
                if (data.one == 1 && data.two == 1 && data.three == 1 && data.four == 1) {
                    canchou = !0
                }
                if (data.one != 1) {
                    shannum = 1
                } else if (data.two != 1) {
                    shannum = 2
                } else if (data.three != 1) {
                    shannum = 3
                } else if (data.four != 1) {
                    shannum = 4
                }
                this.setState({ data: res.data, shannum, canchou })
            } else {
                this.setState({ shannum: 1 })
            }
        })

        //  console.log(liststr?'1':'2','liststr');
        // let list = JSON.parse(localStorage.getItem('orderlist')) || []
        // console.log(list, 'list');

        // this.setState({ list }, () => {
        //     this.getamount()
        // })
        // this.getdata()

    }
    go(e) {
        let { data } = this.state, cango = !0
        switch (e) {
            case 1: { if (data.one == 1) { cango = !1 } break; }
            case 2: { if (data.two == 1) { cango = !1 } break; }
            case 3: { if (data.three == 1) { cango = !1 } break; }
            case 4: { if (data.four == 1) { cango = !1 } break; }

            default:
                break;
        }
        if (cango) {
            window.location.href = './detail.html?type=' + e
        }
    }





    quit() {
        let { time } = this.state
        if (time == 5) {
            localStorage.removeItem('phone')
            localStorage.removeItem('userid')
            localStorage.removeItem('token')
            window.location.href = './index.html'
        } else {
            console.log(time, 'time');
            this.setState({ time: time + 1 })
        }
    }

    playmusic() {
        var bgMusic = document.getElementById('bgmusic'), { playing } = this.state
        if (playing) {
            bgMusic.pause()
        } else {
            bgMusic.play();
        }
        this.setState({ playing: !playing })
    }

    selectchange(e) {
        let { value } = e.target
        this.setState({ sizeid: value })
    }

    selectchange1(e) {
        let { value } = e.target, { amount, allprice } = this.state;
        if (value == 0) {
            amount = 610
        } if (value == -1) {
            amount = 300
        } if (value == 1) {
            amount = 835
        }
        this.setState({ cpid: value, amount })
    }


    render() {
        let { myphone, data, shannum, playing, canchou, sizeid, cphtml, cpid } = this.state;
        //  console.log(sizehtml, 'sizehtml');
        return (
            <div id="app">
                <div className="myinfo">您好,{myphone}</div>
                <audio preload="auto" src="music.mp3" loop id="bgmusic" >
                </audio>
                <img onClick={this.playmusic.bind(this)} className={"musicicon " + (playing ? 'zhuan' : '')} src="./src/music.png" alt="" />
                <img className="bg" src="./src/main_bg.png" alt="" />
                <img onClick={() => {
                    window.location.href = './hdsm.html'
                }} className="hdsm" src="./src/hdsm.png" alt="" />
                <div className="part">
                    <img className="moonbg" src="./src/moon.png" alt="" />
                    <div className="liang top">
                        <img className={'parttt '} style={{ opacity: data.one == 1 ? '1' : '0' }} onClick={this.go.bind(this, '1')} src={`./src/moon1_c.png`} alt="" />
                        <img className={'parttt '} style={{ opacity: data.two == 1 ? '1' : '0' }} onClick={this.go.bind(this, '2')} src={`./src/moon2_c.png`} alt="" />
                    </div>
                    <div className="liang">
                        <img className={'parttt '} style={{ opacity: data.three == 1 ? '1' : '0' }} onClick={this.go.bind(this, '3')} src={`./src/moon3_c.png`} alt="" />
                        <img className={'parttt '} style={{ opacity: data.four == 1 ? '1' : '0' }} onClick={this.go.bind(this, '4')} src={`./src/moon4_c.png`} alt="" />
                    </div>

                    <div>
                        <img className={'partt ' + (shannum == 1 ? 's' : '')} onClick={this.go.bind(this, '1')} src={`./src/moon1.png`} alt="" />



                        <img className={'partt ' + (shannum == 2 ? 's' : '')} onClick={this.go.bind(this, '2')} src={`./src/moon2.png`} alt="" />
                    </div>
                    <div>
                        <img className={'partt ' + (shannum == 3 ? 's' : '')} onClick={this.go.bind(this, '3')} src={`./src/moon3.png`} alt="" />
                        <img className={'partt ' + (shannum == 4 ? 's' : '')} onClick={this.go.bind(this, '4')} src={`./src/moon4.png`} alt="" />
                    </div>
                    {/* <div>
                        <img onClick={this.go.bind(this,'1')} src={`./src/moon1${data.one == 1 ? '_c' : ''}.png`} alt="" />
                        <img onClick={this.go.bind(this,'2')}src={`./src/moon2${data.two == 1 ? '_c' : ''}.png`} alt="" />
                    </div>
                    <div>
                        <img onClick={this.go.bind(this,'3')}src={`./src/moon3${data.three == 1 ? '_c' : ''}.png`} alt="" />
                        <img onClick={this.go.bind(this,'4')}src={`./src/moon4${data.four == 1 ? '_c' : ''}.png`} alt="" />
                    </div> */}

                </div>
                <div className="btns">
                    <img className={canchou?'gochou':''}  onClick={() => {
                        window.location.href = './lottery.html'
                    }} src={"./src/" + (canchou ? 'gochou' : 'main_btn1') + ".png"} alt="" />
                    <img onClick={() => {
                        window.location.href = './mygift.html'
                    }} src="./src/main_btn2.png" alt="" />
                </div>
                {/* <img src="./src/main_2.png" alt="" />
                <img src="./src/main_3.png" alt="" /> */}

            </div>
        )
    }
}

ReactDOM.render(
    <div>
        {/* <TopLine /> */}
        <div id='body'>
            {/* <Tabbar index='1' /> */}
            <Main />
        </div>
    </div>
    // <Barrage />
    , $('.container')[0]
)